package com.guldan.jaina.task;

import com.guldan.jaina.dto.citizeninfo.CitizenInfoDTO;
import com.guldan.jaina.manager.CitizenInfoManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by Silas.
 * Date: 2017/1/12
 * Time: 23:27
 */
public class DownCitizenThread implements Runnable {

    public Logger logger = LoggerFactory.getLogger(getClass());

    private LinkedBlockingQueue<CitizenInfoDTO> queue;
    private LinkedBlockingQueue<CitizenInfoDTO> data;
    private CitizenInfoManager citizenInfoManager;
    private String threadName;

    public void setQueue(LinkedBlockingQueue<CitizenInfoDTO> queue) {
        this.queue = queue;
    }

    public void setData(LinkedBlockingQueue<CitizenInfoDTO> data) {
        this.data = data;
    }

    public void setCitizenInfoManager(CitizenInfoManager citizenInfoManager) {
        this.citizenInfoManager = citizenInfoManager;
    }

    public void setThreadName(String threadName) {
        this.threadName = threadName;
    }

    @Override
    public void run() {
        int count = 0;
        try {

            logger.info(this.threadName + " queue.size=" + queue.size());

            while (!queue.isEmpty()) {
                CitizenInfoDTO d = queue.take();
                d = citizenInfoManager.getCitizenDTOForDown(d);
                data.put(d);
                count++;
            }
        } catch (InterruptedException e) {
            logger.error("1111111111111111 error");
            e.printStackTrace();
        } finally {
            logger.info(this.threadName + " count=" + count);
        }
    }


}
